//==========================================================================
// Copyright (c) 2000-2008,  Elastos, Inc.  All Rights Reserved.
//==========================================================================
#ifndef __NOTIFIERCENTER_H__
#define __NOTIFIERCENTER_H__

#include <driver.h>
#include <drv_hook.h>

#define EVENT_KEYPAD    1
#define EVENT_TOUCH     2

#define SERVICE_KEYPAD  3
#define SERVICE_MOUSE   4

class CNotifierCenter: public CDeviceDriver
{
public:
    CARAPI Read(
        /* [in] */ Int64 u64Offset,
        /* [in] */ Int32 uNumberOfBytesToRead,
        /* [out] */ MemoryBuf * pData,
        /* [out] */ IEvent * * ppCompletionEvent);

    CARAPI Write(
        /* [in] */ Int64 u64Offset,
        /* [in] */ const MemoryBuf & ebbData,
        /* [out] */ Int32 * puNumberOfBytesWritten,
        /* [out] */ IEvent * * ppCompletionEvent);

    CARAPI Control(
        /* [in] */ Handle32 nControlCode,
        /* [in] */ const MemoryBuf & ebbInData,
        /* [out] */ MemoryBuf * pOutData,
        /* [out] */ IEvent * * ppCompletionEvent);

    virtual void Dispose() {}

public:
    ECode AddNotifier(
        /* [in] */ Int32 type,
        /* [in] */ const PVoid pNotifierProc);

    void CallNotifier(
        /* [in] */ Int32 type,
        /* [in] */ Int32 code,
        /* [in] */ PVoid  pParam);

    void RemoveNotifier(
        /* [in] */ Int32 type);
public:
    CNotifierCenter(Int32 capacity = 256);
    ~CNotifierCenter();

private:
    Hook  m_hook;
   // RTL_CRITICAL_SECTION m_hLock;
};

extern CNotifierCenter g_notifierCenter;

inline ECode AddNotifier(Int32 type, const PVoid proc)
{
     return g_notifierCenter.AddNotifier(type, proc);
}

inline void CallNotifier(Int32 type, Int32 code, PVoid pParam)
{
    g_notifierCenter.CallNotifier(type, code, pParam);
}

inline void RemoveNotifier(Int32 type)
{
    g_notifierCenter.RemoveNotifier(type);
}

#endif //__NOTIFIERCENTER_H__

